void reverseLinkedList(struct ListNode *head) {
    struct ListNode *pre = NULL;
    struct ListNode *cur = head;

    while (cur != NULL) {
        struct ListNode *next = cur->next;
        cur->next = pre;
        pre = cur;
        cur = next;
    }
}

struct ListNode *reverseBetween(struct ListNode *head, int left, int right) {
    struct ListNode *dummyNode = malloc(sizeof(struct ListNode));
    dummyNode->val = -1;
    dummyNode->next = head;

    struct ListNode *pre = dummyNode;
    for (int x=0;x<left-1;x++) {
        pre=pre->next;
    }

    struct ListNode *rightNode = pre;
    for (int x= 0;x<right-left+1;x++) {
        rightNode = rightNode->next;
    }

    struct ListNode *leftNode = pre->next;
    struct ListNode *curr = rightNode->next;

    pre->next = NULL;
    rightNode->next = NULL;

    reverseLinkedList(leftNode);

    pre->next = rightNode;
    leftNode->next = curr;
    return dummyNode->next;
}